
<template >
  <div class="load-container">
    <image class="image" :src="logo" resize='cover'></image>
    <input class="input" auto-appear="false" placeholder="请输入员工编号" @input="chnageUserName" :value="userCode"></input>
    <input class="input" auto-appear="false" placeholder="请输入密码" @input="changePassword" :value="userKey"></input>
    <wxc-button class="button" text="确定" @wxcButtonClicked="wxcButtonClicked">
    </wxc-button>
    <wxc-loading :show="isShow" type="default" loading-text="登录中"></wxc-loading>

  </div>

</template>

<script>
  import { WxcButton ,WxcLoading,WxcPartLoading} from 'weex-ui';
  var modal = weex.requireModule('modal')
  const Server = require('./afNetwork.js')
  const utils = require('./lib/utils')
  const navigator = weex.requireModule('navigator');
  import Root from './rootView.js'

  export default {
    components: { WxcButton,WxcLoading,WxcPartLoading},

    data() {
      return {
        logo:'https://gd2.alicdn.com/bao/uploaded/i2/T14H1LFwBcXXXXXXXX_!!0-item_pic.jpg',
        userCode:'WW00028',
        userKey:'123456',
        isShow:false
      }
    },

    methods: {

      chnageUserName(e) {
        this.userCode = e.value
      },

      changePassword(e) {
        this.userKey = e.value
      },

      wxcButtonClicked(e) {
        if(this.userCode === null || this.userCode.length == 0) {
          modal.toast({ message: '请输入员工编号',duraction:1000})
          return
        } else if (this.userKey === null || this.userKey.length == 0) {
          modal.toast({ message: '请输入密码',duraction:1000})
          return
        }
        console.log(this.userCode+this.userKey);

        this.isShow = true
        //
        var pamas = {
          'staff_code':this.userCode,
          'password':this.userKey,
          'os_type':weex.config.env.platform,
          'os_imei':"cde167c06ec87b82397adc425ef477cd01aad107",
          'os_version':weex.config.env.deviceModel,
          'app_version':weex.config.env.appVersion,
          'time':'1111'
        }

        var me = this

        Server.getFetch('api/App/app_login',pamas,function(data){
          console.log(data);
          me.isShow = false
          if (data.ok == false) {
            modal.toast({ message:data.data.message,duraction:2000})
            me.pushHomeView()
          }
        })

      },

      pushHomeView() {
      //! 报错账号 密码
      Root.saveItem(this.userCode,"userName")
      Root.saveItem(this.userKey,"userPassword")
      Root.saveItem("48205","userId")


        console.log(666);
        const url = weex.config.bundleUrl;
        var newUrl = utils.setBundleUrl(url, 'base.js');
        navigator.push({
            url: newUrl+'',
            animated: "true"
        }, event => {
            modal.toast({ message: 'callback: ' + newUrl,duraction:1000})
        })
      }


    }

  }
</script>

<style scoped>
  .load-container {
    width: 750px;
    height: 1250px;
    background-color: red;

  }
  .image {
    margin-top: 200px;
    width: 750px;
    height: 500px;
  }

  .input {
    width: 700px;
    margin-top: 50px;
    margin-left: 40px;
  }

  .button {
    width: 700px;
    justify-content: center;
    margin-top: 100px;
    margin-left: 25px;
  }







</style>
